package com.home.wechat_.ui

import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.ViewModel
import com.home.wechat_.R
import com.home.wechat_.ui.data.Chat
import com.home.wechat_.ui.data.Module
import com.home.wechat_.ui.data.Msg
import com.home.wechat_.ui.data.User
import com.home.wechat_.ui.theme.WeTheme

/**
 *Author: YFS(893145181@qq.com)
 *Time:2021/12/1 10:26
 */
class WeViewModel : ViewModel() {
    var selectedTab by mutableStateOf(0)

    var theme by mutableStateOf(WeTheme.Theme.Light)


    var chats by mutableStateOf(
        listOf(
            Chat(
                friend = User("gaolaoshi", "高老师", R.drawable.avatar_gaolaoshi),
                mutableStateListOf(
                    Msg(User("gaolaoshi", "高老师", R.drawable.avatar_gaolaoshi), "锄禾日当午", "14:20"),
                    Msg(User.Me, "汗滴禾下土", "14:20"),
                    Msg(User("gaolaoshi", "高老师", R.drawable.avatar_gaolaoshi), "谁知盘中餐", "14:20"),
                    Msg(User.Me, "粒粒皆辛苦", "14:20"),
                    Msg(
                        User("gaolaoshi", "高老师", R.drawable.avatar_gaolaoshi),
                        "唧唧复唧唧，木兰当户织。不闻机杼声，惟闻女叹息。",
                        "14:20"
                    ),
                    Msg(User.Me, "双兔傍地走，安能辨我是雄雌？", "14:20"),
                    Msg(
                        User("gaolaoshi", "高老师", R.drawable.avatar_gaolaoshi),
                        "床前明月光，疑是地上霜。",
                        "14:20"
                    ),
                    Msg(User.Me, "吃饭吧？", "14:20"),
                )
            ),
            Chat(
                friend = User("diuwuxian", "丢物线", R.drawable.avatar_diuwuxian),
                mutableStateListOf(
                    Msg(User("diuwuxian", "丢物线", R.drawable.avatar_diuwuxian), "哈哈哈", "13:48"),
                    Msg(User.Me, "你笑个屁呀", "13:48").apply {
                        read = true
                    },
                )
            ),
        )
    )


    //页面跳转模块
    var openModule : Module? by mutableStateOf(null)
    var currentChat:Chat? by mutableStateOf(null)


    fun startChat(chat:Chat){
        currentChat = chat
        openModule = Module.Chat
    }

    fun endChat() {
        openModule =null
    }

    fun read(chat: Chat) {
        for (msg in chat.msgs) {
            msg.read = true
        }
    }

    fun boom(chat: Chat) {
        chat.msgs.add(Msg(User.Me, "\uD83D\uDCA3","13:48").apply { read = true })
    }
}